from fastapi import APIRouter, Depends

from forward.api.admin.schemas.channel import (
    ChannelOaInSchema,
    ChannelOaMenusInSchema,
    ChannelH5InSchema,
    ChannelMpInSchema,
    ChannelWxInSchema,
    ChannelOaReplyDefaultDetailInSchema,
    ChannelOaReplyDefaultCreateInSchema,
    ChannelOaReplyDefaultEditInSchema,
    ChannelOaReplyDefaultDelInSchema,
    ChannelOaReplyDefaultStatusInSchema,
    ChannelOaReplyFollowDetailInSchema,
    ChannelOaReplyFollowCreateInSchema,
    ChannelOaReplyFollowEditInSchema,
    ChannelOaReplyFollowDelInSchema,
    ChannelOaReplyFollowStatusInSchema,
    ChannelOaReplyKeywordDetailInSchema,
    ChannelOaReplyKeywordCreateInSchema,
    ChannelOaReplyKeywordEditInSchema,
    ChannelOaReplyKeywordDelInSchema,
    ChannelOaReplyKeywordStatusInSchema,
    ChannelOaReplyOutSchema,
)
from forward.api.admin.service.channel.h5 import ChannelH5Service
from forward.api.admin.service.channel.mp import ChannelMpService
from forward.api.admin.service.channel.oa import ChannelOaService
from forward.api.admin.service.channel.oa_menu import ChannelOaMenuService
from forward.api.admin.service.channel.oa_reply_default import (
    ChannelOaReplyDefaultService,
)
from forward.api.admin.service.channel.oa_reply_follow import (
    ChannelOaReplyFollowService,
)
from forward.api.admin.service.channel.oa_reply_keyword import (
    ChannelOaReplyKeywordService,
)
from forward.api.admin.service.channel.wx import ChannelWxService
from forward.dependencies.log import record_log
from forward.http_base import unified_resp
from forward.schema_base import PageInationResult

router = APIRouter(prefix="/channel")


@router.get("/oa/detail")
@unified_resp
async def oa_detail(oa_service: ChannelOaService = Depends(ChannelOaService.instance)):
    """公众号渠道设置详情"""
    return await oa_service.detail()


# @router.post("/oa/save", dependencies=[Depends(record_log(title="公众号渠道设置保存"))])
@router.post("/oa/save")
@unified_resp
async def oa_save(
    oa_in: ChannelOaInSchema,
    oa_service: ChannelOaService = Depends(ChannelOaService.instance),
):
    """公众号渠道设置保存"""
    return await oa_service.save(oa_in)


@router.get("/oaMenu/detail")
@unified_resp
async def oa_menu_detail(
    menu_service: ChannelOaMenuService = Depends(ChannelOaMenuService.instance),
):
    """公众号菜单详情"""
    return await menu_service.detail()


@router.post("/oaMenu/save")
@unified_resp
async def oa_menu_save(
    menus_in: ChannelOaMenusInSchema,
    menu_service: ChannelOaMenuService = Depends(ChannelOaMenuService.instance),
):
    """公众号仅是保存菜单"""
    return await menu_service.save(menus_in, False)


@router.post("/oaMenu/publish")
@unified_resp
async def oa_menu_publish(
    menus_in: ChannelOaMenusInSchema,
    menu_service: ChannelOaMenuService = Depends(ChannelOaMenuService.instance),
):
    """公众号保存并发布菜单"""
    return await menu_service.save(menus_in, True)


@router.get("/h5/detail")
@unified_resp
async def h5_detail(h5_service: ChannelH5Service = Depends(ChannelH5Service.instance)):
    """H5渠道设置详情"""
    return await h5_service.detail()


@router.post("/h5/save", dependencies=[Depends(record_log(title="H5渠道设置保存"))])
@unified_resp
async def h5_save(
    h5_in: ChannelH5InSchema,
    h5_service: ChannelH5Service = Depends(ChannelH5Service.instance),
):
    """H5渠道设置保存"""
    return await h5_service.save(h5_in)


@router.get("/mp/detail")
@unified_resp
async def mp_detail(mp_service: ChannelMpService = Depends(ChannelMpService.instance)):
    """微信小程序渠道设置详情"""
    return await mp_service.detail()


@router.post(
    "/mp/save", dependencies=[Depends(record_log(title="微信小程序渠道设置保存"))]
)
@unified_resp
async def mp_save(
    mp_in: ChannelMpInSchema,
    mp_service: ChannelMpService = Depends(ChannelMpService.instance),
):
    """微信小程序渠道设置保存"""
    return await mp_service.save(mp_in)


@router.get("/wx/detail")
@unified_resp
async def wx_detail(wx_service: ChannelWxService = Depends(ChannelWxService.instance)):
    """开放平台渠道设置详情"""
    return await wx_service.detail()


@router.post(
    "/wx/save", dependencies=[Depends(record_log(title="开放平台渠道设置保存"))]
)
@unified_resp
async def wx_save(
    wx_in: ChannelWxInSchema,
    wx_service: ChannelWxService = Depends(ChannelWxService.instance),
):
    """开放平台渠道设置保存"""
    return await wx_service.save(wx_in)


@router.get(
    "/oaReplyDefault/list", response_model=PageInationResult[ChannelOaReplyOutSchema]
)
@unified_resp
async def oa_reply_default_list(
    ord_service: ChannelOaReplyDefaultService = Depends(
        ChannelOaReplyDefaultService.instance
    ),
):
    """公众号默认回复列表"""
    return await ord_service.list()


@router.get("/oaReplyDefault/detail")
@unified_resp
async def oa_reply_default_detail(
    detail_in: ChannelOaReplyDefaultDetailInSchema = Depends(),
    ord_service: ChannelOaReplyDefaultService = Depends(
        ChannelOaReplyDefaultService.instance
    ),
):
    """公众号默认回复详情"""
    return await ord_service.detail(detail_in.id)


@router.post("/oaReplyDefault/add")
@unified_resp
async def oa_reply_default_add(
    create_in: ChannelOaReplyDefaultCreateInSchema,
    ord_service: ChannelOaReplyDefaultService = Depends(
        ChannelOaReplyDefaultService.instance
    ),
):
    """公众号默认回复新增"""
    return await ord_service.add(create_in)


@router.post("/oaReplyDefault/edit")
@unified_resp
async def oa_reply_default_edit(
    edit_in: ChannelOaReplyDefaultEditInSchema,
    ord_service: ChannelOaReplyDefaultService = Depends(
        ChannelOaReplyDefaultService.instance
    ),
):
    """公众号默认回复编辑"""
    return await ord_service.edit(edit_in)


@router.post("/oaReplyDefault/del")
@unified_resp
async def oa_reply_default_del(
    del_in: ChannelOaReplyDefaultDelInSchema,
    ord_service: ChannelOaReplyDefaultService = Depends(
        ChannelOaReplyDefaultService.instance
    ),
):
    """公众号默认回复删除"""
    return await ord_service.delete(del_in.id)


@router.post("/oaReplyDefault/status")
@unified_resp
async def oa_reply_default_status(
    status_in: ChannelOaReplyDefaultStatusInSchema,
    ord_service: ChannelOaReplyDefaultService = Depends(
        ChannelOaReplyDefaultService.instance
    ),
):
    """公众号默认回复状态"""
    return await ord_service.status(status_in.id)


@router.get(
    "/oaReplyFollow/list", response_model=PageInationResult[ChannelOaReplyOutSchema]
)
@unified_resp
async def oa_reply_follow_list(
    orf_service: ChannelOaReplyFollowService = Depends(
        ChannelOaReplyFollowService.instance
    ),
):
    """公众号关注回复列表"""
    return await orf_service.list()


@router.get("/oaReplyFollow/detail")
@unified_resp
async def oa_reply_follow_detail(
    detail_in: ChannelOaReplyFollowDetailInSchema = Depends(),
    orf_service: ChannelOaReplyFollowService = Depends(
        ChannelOaReplyFollowService.instance
    ),
):
    """公众号关注回复详情"""
    return await orf_service.detail(detail_in.id)


@router.post("/oaReplyFollow/add")
@unified_resp
async def oa_reply_follow_add(
    create_in: ChannelOaReplyFollowCreateInSchema,
    orf_service: ChannelOaReplyFollowService = Depends(
        ChannelOaReplyFollowService.instance
    ),
):
    """公众号关注回复新增"""
    return await orf_service.add(create_in)


@router.post("/oaReplyFollow/edit")
@unified_resp
async def oa_reply_follow_edit(
    edit_in: ChannelOaReplyFollowEditInSchema,
    orf_service: ChannelOaReplyFollowService = Depends(
        ChannelOaReplyFollowService.instance
    ),
):
    """公众号关注回复编辑"""
    return await orf_service.edit(edit_in)


@router.post("/oaReplyFollow/del")
@unified_resp
async def oa_reply_follow_del(
    del_in: ChannelOaReplyFollowDelInSchema,
    orf_service: ChannelOaReplyFollowService = Depends(
        ChannelOaReplyFollowService.instance
    ),
):
    """公众号关注回复删除"""
    return await orf_service.delete(del_in.id)


@router.post("/oaReplyFollow/status")
@unified_resp
async def oa_reply_follow_status(
    status_in: ChannelOaReplyFollowStatusInSchema,
    orf_service: ChannelOaReplyFollowService = Depends(
        ChannelOaReplyFollowService.instance
    ),
):
    """公众号关注回复状态"""
    return await orf_service.status(status_in.id)


@router.get(
    "/oaReplyKeyword/list", response_model=PageInationResult[ChannelOaReplyOutSchema]
)
@unified_resp
async def oa_reply_keyword_list(
    ork_service: ChannelOaReplyKeywordService = Depends(
        ChannelOaReplyKeywordService.instance
    ),
):
    """公众号关键词回复列表"""
    return await ork_service.list()


@router.get("/oaReplyKeyword/detail")
@unified_resp
async def oa_reply_keyword_detail(
    detail_in: ChannelOaReplyKeywordDetailInSchema = Depends(),
    ork_service: ChannelOaReplyKeywordService = Depends(
        ChannelOaReplyKeywordService.instance
    ),
):
    """公众号关键词回复详情"""
    return await ork_service.detail(detail_in.id)


@router.post("/oaReplyKeyword/add")
@unified_resp
async def oa_reply_keyword_add(
    create_in: ChannelOaReplyKeywordCreateInSchema,
    ork_service: ChannelOaReplyKeywordService = Depends(
        ChannelOaReplyKeywordService.instance
    ),
):
    """公众号关键词回复新增"""
    return await ork_service.add(create_in)


@router.post("/oaReplyKeyword/edit")
@unified_resp
async def oa_reply_keyword_edit(
    edit_in: ChannelOaReplyKeywordEditInSchema,
    ork_service: ChannelOaReplyKeywordService = Depends(
        ChannelOaReplyKeywordService.instance
    ),
):
    """公众号关键词回复编辑"""
    return await ork_service.edit(edit_in)


@router.post("/oaReplyKeyword/del")
@unified_resp
async def oa_reply_keyword_del(
    del_in: ChannelOaReplyKeywordDelInSchema,
    ork_service: ChannelOaReplyKeywordService = Depends(
        ChannelOaReplyKeywordService.instance
    ),
):
    """公众号关键词回复删除"""
    return await ork_service.delete(del_in.id)


@router.post("/oaReplyKeyword/status")
@unified_resp
async def oa_reply_keyword_status(
    status_in: ChannelOaReplyKeywordStatusInSchema,
    ork_service: ChannelOaReplyKeywordService = Depends(
        ChannelOaReplyKeywordService.instance
    ),
):
    """公众号关键词回复状态"""
    return await ork_service.status(status_in.id)
